package com.bazinga.contact.view;

import java.util.List;
import java.util.Map;

import com.bazinga.contact.controller.JobDetailsManager;
import com.bazinga.contact.controller.JobScheduleManager;
import com.bazinga.contact.model.JobDetails;
import com.bazinga.contact.model.JobSchedule;
import com.opensymphony.xwork2.ActionSupport;


public class JobDetailsAction extends ActionSupport{

	private static final long serialVersionUID = 9149826260758390091L;
	private JobDetails jobDetails;
	private List<JobSchedule> jobScheduleList;
	private Long id;
	private Map<String, Object> session;
	private String daysofweek="";
	private String startTime;
	private String endTime;
	
	private JobDetailsManager linkController;
	private JobScheduleManager jsLinkController;
	
	public JobDetails getJobDetails() {
		return jobDetails;
	}

	public void setJobDetails(JobDetails jobDetails) {
		this.jobDetails = jobDetails;
	}

	public JobDetailsAction() {
		linkController = new JobDetailsManager();
		jsLinkController = new JobScheduleManager();
	}

	public String execute() {
		jobDetails = linkController.getById(id);
		
		if(jobDetails.getSkill1().equals("1"))
			jobDetails.setSkill1("Web Development");
		else if(jobDetails.getSkill1().equals("2"))
			jobDetails.setSkill1("Java");
		else if(jobDetails.getSkill1().equals("3"))
			jobDetails.setSkill1("Library Management");
		else if(jobDetails.getSkill1().equals("4"))
			jobDetails.setSkill1("Cashier");
		else if(jobDetails.getSkill1().equals("5"))
			jobDetails.setSkill1("Chef");
		
		if(jobDetails.getSkill2().equals("1"))
			jobDetails.setSkill2("Web Development");
		else if(jobDetails.getSkill2().equals("2"))
			jobDetails.setSkill2("Java");
		else if(jobDetails.getSkill2().equals("3"))
			jobDetails.setSkill2("Library Management");
		else if(jobDetails.getSkill2().equals("4"))
			jobDetails.setSkill2("Cashier");
		else if(jobDetails.getSkill2().equals("5"))
			jobDetails.setSkill2("Chef");
		
		jobScheduleList =  jsLinkController.getByJobId(id);
		for (JobSchedule jobSch:jobScheduleList){
			if("1".equals(jobSch.getDayofweek())){
				daysofweek += " Monday ";
			}else if("2".equals(jobSch.getDayofweek())){
				daysofweek += " Tuesday ";
			}else if("3".equals(jobSch.getDayofweek())){
				daysofweek += " Wednesday ";
			}else if("4".equals(jobSch.getDayofweek())){
				daysofweek += " Thrusday ";
			}else if("5".equals(jobSch.getDayofweek())){
				daysofweek += " Friday ";
			}else if("6".equals(jobSch.getDayofweek())){
				daysofweek += " Saturday ";
			}else if("7".equals(jobSch.getDayofweek())){
				daysofweek += " Sunday ";
			}
			startTime = jobSch.getStart_time().toString();
			endTime = jobSch.getEnd_time().toString();
		}
		return SUCCESS;
	}	

	public String delete() {
		linkController.delete(getId());
		return SUCCESS;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public List<JobSchedule> getJobScheduleList() {
		return jobScheduleList;
	}

	public void setJobScheduleList(List<JobSchedule> jobScheduleList) {
		this.jobScheduleList = jobScheduleList;
	}

	public String getDaysofweek() {
		return daysofweek;
	}

	public void setDaysofweek(String daysofweek) {
		this.daysofweek = daysofweek;
	}

	public String getStartTime() {
		return startTime;
	}

	public void setStartTime(String startTime) {
		this.startTime = startTime;
	}

	public String getEndTime() {
		return endTime;
	}

	public void setEndTime(String endTime) {
		this.endTime = endTime;
	}
	
}
